/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package educar.controllers;


import educar.abmAlumno.AlumnoController;
import educar.abmAsignacionDoc.AsignacionController;
import educar.abmCargos.CargosController;
import educar.abmDedicacion.DedicacionController;
import educar.abmDocente.DocenteController;
import educar.abmFacultad.FacultadController;
import educar.abmMateria.MateriaController;
import educar.abmUsuario.UserController;
import educar.gui.PrincipalView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;


public class PrincipalController implements ActionListener, WindowListener {

    private PrincipalView principalView;

// <editor-fold defaultstate="collapsed" desc="Constructor">
    public PrincipalController(){        
        principalView = new PrincipalView();
        principalView.setListenerButton(this);
        principalView.setListenerWindow(this);
    }
 // </editor-fold>
    
// <editor-fold defaultstate="collapsed" desc="Accion setView">
    public void setView() {
        principalView.setVisible(true);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Action Performed">
    @Override
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if (principalView.getJbAlumno() == source) {
            AlumnoController alumnoController = new AlumnoController(this);
            alumnoController.setView();
            principalView.setVisible(false);
            }
        if (principalView.getJbCargo() == source) {
            CargosController cargosController = new CargosController(this);
            cargosController.setView();
            principalView.setVisible(false);        
        }
        if (principalView.getJbDocente() == source) {
            DocenteController docenteController = new DocenteController(this);
            docenteController.setView();
            principalView.setVisible(false);
        }
        if (principalView.getJbFacultad() == source) {
            FacultadController facultadController = new FacultadController(this);
            facultadController.setView();
            principalView.setVisible(false);
            
        }
        if (principalView.getJbMateria() == source) {
            MateriaController materiaController = new MateriaController(this);
            materiaController.setView();
            principalView.setVisible(false);
        }
        if (principalView.getJbUsuario() == source) {
            UserController userController = new UserController(this);
            userController.setView();
            principalView.setVisible(false);
        }
        if (principalView.getJbDedicacion() == source) {
            DedicacionController dedicacionController = new DedicacionController(this);
            dedicacionController.setView();
            principalView.setVisible(false);
        }
         if (principalView.getJbAsignacion() == source) {
            AsignacionController asignacionController = new AsignacionController(this);
            asignacionController.setView();
            principalView.setVisible(false);
        }
        
        
    }//Fin del metodo actionPerformed().
    
 // </editor-fold>
    
    @Override
    public void windowClosing(WindowEvent e) {    
        Object source = e.getSource();
        if (principalView.getVentana() == source) {
            int op = JOptionPane.showConfirmDialog(null,"Esta seguro que desea salir de la aplicacion?","Confirmar cierre del programa", JOptionPane.YES_NO_OPTION);
            if (op == JOptionPane.YES_OPTION){
                System.exit(0);
            }
        }
    }
    
// <editor-fold defaultstate="collapsed" desc="Acciones No Usada">
    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowActivated(WindowEvent e) {
    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
// </editor-fold>

}//Fin de la clase PrincipalController.
